{% extends  data.theme + "/_base.html" %}

{% import "bootstrap/wtf.html" as wtf %}

{% block title %} {{data.title}} {% endblock %}

{%- block head -%} 
{{ super() }}
{%- endblock -%}

{%- block body -%}

<!--div class="page-header"> </div-->
<div class="container">
<div class="row">
  <div class="col-lg-offset col-lg-6">
    <div class="input-group">
      <span class="input-group-btn">
        <button class="btn btn-info" type="button" id="addtag">+</button>
      </span>
      <input type="text" class="form-control" placeholder="关键字" aria-label="keywords">
      <span class="input-group-btn">
        <button class="btn btn-info" type="button">Search</button>
      </span>
    </div>
  </div>
</div>
</div>

<div class="clearfix" style="margin-bottom: 15px;"></div>

{#{ hello("Hello,world!") }#}

<div class="container"><div class="row"><div class="col-md-12">
<div class="panel-group" id="accordion">
{% for tag in data['rows'] %}
    <div class="panel panel-default" data-id="{{tag.id}}">
        <div class="panel-heading">
            <h4 class="panel-title">
<button type="button" class="btn btn-primary btn-xs edit " data-id="{{tag.id}}">编辑</button>
<a class="badge pull-right badge-info linkscount">{{tag.urls|length}}</a>
<a class="collapsed " data-parent="#accordion" data-id="{{tag.id}}" data-toggle="collapse" href="#collapse-{{tag.id}}">
<span class="label label-default">{{ tag.name }}</span></a>
            </h4>
        </div>
		<div id="collapse-{{tag.id}}" class="panel-collapse collapse">
            <div class="panel-body">
			<blockquote>
				{{ tag.content }}
				 <!--small>可以设置右对齐</small-->
			</blockquote>
            </div>
        </div>
    </div>   
{% endfor %}
</div>

</div> </div> </div>

{% endblock %}

{% block script %}
{{ super() }}
<script type="text/javascript">
$(function() {
	//$('#btn_save').on("click",function(){
	//});
	$(".edit").on("click",function(){
		var id=$(this).attr("data-id");
		location.href="tag_edit/"+id;
	});

	$(".linkscount").on("click",function(){
		var id=$(this).closest(".panel").attr("data-id");
		postJson("tagurls/"+id+".json",function(data,status,xhr){
			//console.log(data); //resp["data"]
			//console.log(this); //当前this要的resp,没要req,只有xhr
			//console.log(xhr);
			var ul= $("<ul></ul>");
			var links= $.map(data,function(one){
				var li= $("<li></li>");
				var a= $("<a></a>").attr("href",one.url).html(one.title);
				return li.append(a).append(" " + one.url);
			})
			ul.append(links);

			showPopup(ul,"链接");
		});
	});

	$("#addtag").on("click",function(){
		location.href="tag_edit";
	});
});
</script>
{% endblock %}
